import { ContentTypeEnum } from '@/enums/httpEnum';
import { defHttp } from '@/utils/http/axios';
import { DeptListItem, DeptListGetResultModel } from './model/systemModel';

enum Api {
  Dept = '/dept/',
  List = '/dept/list',
}

export const getDeptList = (params?: DeptListItem) =>
  defHttp.get<DeptListGetResultModel>({
    url: Api.List,
    params,
    headers: { PermsCode: 'dept:list' },
  });

export const addDepartment = (
  name: string,
  parentId: Number,
  remark: string,
  sortNo: Number,
  status: Number,
) =>
  defHttp.post({
    url: Api.Dept,
    params: { name, parentId, remark, sortNo, status },
    headers: { 'Content-Type': ContentTypeEnum.FORM_DATA, PermsCode: 'dept:create' },
  });

/**
 * 删除部门
 * @param id
 * @returns
 */
export const delDepartment = (id: Number) =>
  defHttp.delete({ url: `${Api.Dept}${id}`, params: { id } }, { isTransformResponse: false });

/**
 * 部门更新
 * @param id
 * @param name
 * @param parentId
 * @param remark
 * @param sortNo
 * @param status
 * @returns
 */
export const updateDepartment = (
  id: Number,
  name: string,
  parentId: Number,
  remark: string,
  sortNo: Number,
  status: Number,
) =>
  defHttp.post(
    {
      url: `${Api.Dept}${id}`,
      params: { id, name, parentId, remark, sortNo, status },
      headers: { 'Content-Type': ContentTypeEnum.FORM_DATA, PermsCode: 'dept:update' },
    },
    { isTransformResponse: false },
  );
